var e = require("../../../../@babel/runtime/helpers/regeneratorRuntime"), t = require("../../../../@babel/runtime/helpers/asyncToGenerator"), n = require("../../../../@babel/runtime/helpers/classCallCheck"), r = require("../../../../@babel/runtime/helpers/createClass"), a = require("../../../../common/vendor.js"), i = require("../function/index.js"), o = new (function() {
    function o() {
        n(this, o), this.config = {
            type: "navigateTo",
            url: "",
            delta: 1,
            params: {},
            animationType: "pop-in",
            animationDuration: 300,
            intercept: !1,
            events: {}
        }, this.route = this.route.bind(this);
    }
    var u;
    return r(o, [ {
        key: "addRootPath",
        value: function(e) {
            return "/" === e[0] ? e : "/".concat(e);
        }
    }, {
        key: "mixinParam",
        value: function(e, t) {
            e = e && this.addRootPath(e);
            var n = "";
            return /.*\/.*\?.*=.*/.test(e) ? (n = i.queryParams(t, !1), e + "&".concat(n)) : e + (n = i.queryParams(t));
        }
    }, {
        key: "route",
        value: (u = t(e().mark(function t() {
            var n, r, a, o = arguments;
            return e().wrap(function(e) {
                for (;;) switch (e.prev = e.next) {
                  case 0:
                    if (n = o.length > 0 && void 0 !== o[0] ? o[0] : {}, r = o.length > 1 && void 0 !== o[1] ? o[1] : {}, 
                    a = {}, "string" == typeof n ? (a.url = this.mixinParam(n, r), a.type = "navigateTo") : (a = i.deepMerge(this.config, n)).url = this.mixinParam(n.url, n.params), 
                    a.url === i.page()) {
                        e.next = 13;
                        break;
                    }
                    if (r.intercept && (a.intercept = r.intercept), a.params = r, "function" != typeof (a = i.deepMerge(this.config, a)).intercept) {
                        e.next = 12;
                        break;
                    }
                    return e.next = 7, new Promise(function(e, t) {
                        a.intercept(a, e);
                    });

                  case 7:
                    if (e.t0 = e.sent, !e.t0) {
                        e.next = 10;
                        break;
                    }
                    this.openPage(a);

                  case 10:
                    e.next = 13;
                    break;

                  case 12:
                    this.openPage(a);

                  case 13:
                  case "end":
                    return e.stop();
                }
            }, t, this);
        })), function() {
            return u.apply(this, arguments);
        })
    }, {
        key: "openPage",
        value: function(e) {
            var t = e.url, n = (e.type, e.delta), r = e.animationType, i = e.animationDuration, o = e.events;
            "navigateTo" != e.type && "to" != e.type || a.index.navigateTo({
                url: t,
                animationType: r,
                animationDuration: i,
                events: o
            }), "redirectTo" != e.type && "redirect" != e.type || a.index.redirectTo({
                url: t
            }), "switchTab" != e.type && "tab" != e.type || a.index.switchTab({
                url: t
            }), "reLaunch" != e.type && "launch" != e.type || a.index.reLaunch({
                url: t
            }), "navigateBack" != e.type && "back" != e.type || a.index.navigateBack({
                delta: n
            });
        }
    } ]), o;
}())().route;

exports.route = o;